using System;

namespace MethodHidingExample // 命名空间
{
    public class BaseClass // 基类
    {
        public void Display()
        {
            Console.WriteLine("Display method from BaseClass");
        }
    }

    public class DerivedClass : BaseClass // 派生类
    {
        // 使用 new 关键字隐藏基类的 Display 方法
        public new void Display()
        {
            Console.WriteLine("Display method from DerivedClass");
        }
    }

    public class Program
    {
        public static void Main(string[] args)
        {
            BaseClass baseObject = new BaseClass();
            baseObject.Display(); // 输出: Display method from BaseClass

            DerivedClass derivedObject = new DerivedClass();
            derivedObject.Display(); // 输出: Display method from DerivedClass

            // 使用基类引用指向派生类对象
            BaseClass polymorphicObject = new DerivedClass();
            polymorphicObject.Display(); // 输出: Display method from BaseClass
        }
    }
}
